package com.liuzhongni.wahahanews.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.liuzhongni.wahahanews.R;
import com.liuzhongni.wahahanews.circle.CircleImageView;
import com.liuzhongni.wahahanews.singleton.VolleySingleton;
import com.liuzhongni.wahahanews.topicclass.MyClick;
import com.liuzhongni.wahahanews.topicclass.TopicThird;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/23.lll
 */
public class RecyclerViewAdapterOfTopic extends RecyclerView.Adapter<RecyclerViewAdapterOfTopic.TopicViewHolder> {
    private ArrayList<TopicThird> data;
    private Context context;
    private MyClick myClick;





    public void setMyClick(MyClick myClick) {
        this.myClick = myClick;
    }

    public RecyclerViewAdapterOfTopic(ArrayList<TopicThird> data, Context context) {
        this.data = data;
        this.context = context;

    }

    @Override
    public TopicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.topic_item,null);
        TopicViewHolder holder = new TopicViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final TopicViewHolder holder, int position) {
        int index = holder.getLayoutPosition();
        VolleySingleton.getOurInstance().imgJson(holder.imageViewPic,data.get(index).getPicurl());
        VolleySingleton.getOurInstance().imgJson(holder.imageViewHead,data.get(index).getHeadpicurl());
        holder.textViewName.setText(data.get(index).getName());
        holder.textViewAlias.setText(data.get(index).getAlias());
        holder.textViewReplyCount.setText(data.get(index).getConcernCount() + "关注");
        holder.textViewClassification.setText(data.get(index).getClassification());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(myClick!=null){
                    int index = holder.getLayoutPosition();
                    myClick.itemClick(index);
                    int height = holder.textViewAlias.getLineHeight();
                    int count = holder.textViewAlias.getLineCount();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class TopicViewHolder extends RecyclerView.ViewHolder {
        private NetworkImageView imageViewPic;
        private CircleImageView imageViewHead;
        private TextView textViewName;
        private TextView textViewAlias;
        private TextView textViewReplyCount;
        private TextView textViewClassification;

        public TopicViewHolder(View itemView) {
            super(itemView);
            imageViewPic = (NetworkImageView) itemView.findViewById(R.id.topic_item_iv);
            imageViewHead = (CircleImageView) itemView.findViewById(R.id.topic_item_touxiang);
            textViewName = (TextView) itemView.findViewById(R.id.topic_item_tv_name);
            textViewAlias = (TextView) itemView.findViewById(R.id.topic_item_tv_alias);
            textViewReplyCount = (TextView) itemView.findViewById(R.id.topic_item_tv_replyCount);
            textViewClassification = (TextView) itemView.findViewById(R.id.topic_item_tv_classification);
        }
    }
}
